package com.kunyi.web.service.log.mapper;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.kunyi.web.service.log.entity.domain.LogSafe;
import com.kunyi.web.service.log.entity.req.LogSafeListReq;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Objects;

/**
 * @ClassName LogSafeMapper
 * @Description log_safe表
 * @Author pengjunjun
 * @Date 2024/3/6 14:26
 * @Version 1.0
 **/
@Repository
public interface LogSafeMapper extends BaseMapper<LogSafe> {
    default List<LogSafe> listByReq(LogSafeListReq req) {
        LambdaQueryWrapper<LogSafe> wrapper = Wrappers.lambdaQuery(LogSafe.class)
                .eq(StrUtil.isNotBlank(req.getCode()), LogSafe::getCode, req.getCode())
                .like(StrUtil.isNotBlank(req.getCreateUser()), LogSafe::getCreateUser, req.getCreateUser())
                .eq(StrUtil.isNotBlank(req.getEnvName()), LogSafe::getEnvName, req.getEnvName())
                .eq(Objects.nonNull(req.getEnvType()), LogSafe::getEnvType, req.getEnvType())
                .between(Objects.nonNull(req.getCreateTimeBegin()) && Objects.nonNull(req.getCreateTimeEnd()), LogSafe::getCreateTime, req.getCreateTimeBegin(), req.getCreateTimeEnd())
                .orderByDesc(LogSafe::getCreateTime);
        return selectList(wrapper);
    }
}
